a=[]
for i in range(0,15):
    row=list(map(int,input().split()))
    a.append(row)

b=[]
for i in range(0,4):
    row=list(map(int,input().split()))
    b.append(row)

index=int(input())-1

bi=[-1,-1,-1,-1]
for j in range(0,4):
    for i in range(3,-1,-1):
        if b[i][j]==1:
            bi[j]=i
            break

ai=[15,15,15,15]
for j in range(index,index+4):
    for i in range(0,15):
        if a[i][j]==1:
            ai[j-index]=i
            break

ci=[100,100,100,100]
for i in range(0,4):
    if bi[i]!=-1:
        ci[i]=ai[i]-bi[i]-1

c=min(ci)

for i in range(0,4):
    for j in range(0,4):
        x=i+c
        y=j+index
        if x<15:
            a[x][y]=a[x][y]+b[i][j]

for row in a:
    for col in row:
        print(col,end=" ")
    print("")